package com.vst.serverdatalib.https;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

import com.vst.serverdatalib.R;

public class ToastUtil {
    private static Toast sToast;

    static Toast getInstance(Context context) {
        if (sToast == null) {
            synchronized (ToastUtil.class) {
                if (sToast == null) {
                    sToast = new Toast(context);
                    TextView txt = (TextView) new TextView(context);
                    txt.setBackgroundResource(R.drawable.bg_toast);
                    txt.setGravity(Gravity.CENTER);
                    txt.setPadding(20, 20, 20, 20);
                    txt.setTextColor(Color.LTGRAY);
                    txt.setTextSize(24);
                    sToast.setView(txt);
                }
            }
        }
        return sToast;
    }

    public static void show(Context context, String msg) {
        show(context, msg, Toast.LENGTH_SHORT);
    }

    public static void show(Context context, int resId) {
        show(context, context.getResources().getString(resId), Toast.LENGTH_SHORT);
    }

    public static void show(Context context, String msg, int duration) {
        Toast toast = getInstance(context);
        ((TextView) toast.getView()).setText(msg);
        toast.setDuration(duration);
        toast.show();
    }

}
